cmake_minimum_required(VERSION 3.29)
project(acl_rec)

set(CMAKE_CXX_STANDARD 20)

if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.dev_env")
    file(STRINGS "${CMAKE_SOURCE_DIR}/.dev_env" DEV_ENV_LINES)

    foreach(line IN LISTS DEV_ENV_LINES)
        string(STRIP "${line}" line)
        # 忽略注释行或空行
        if(NOT line MATCHES "^#" AND NOT line STREQUAL "")
            if(line MATCHES "^([^=]+)=(.*)$")
                set(var_name "${CMAKE_MATCH_1}")
                set(var_value "${CMAKE_MATCH_2}")
                string(STRIP "${var_name}" var_name)
                string(STRIP "${var_value}" var_value)
                set(${var_name} "${var_value}")
            endif()
        endif()
    endforeach()
endif()

# 检查 ASCEND_INSTALL_PATH 是否被设置
if(NOT DEFINED ASCEND_INSTALL_PATH)
    message(FATAL_ERROR "ASCEND_INSTALL_PATH is not set. Please set it in .dev_env file.")
endif()

# 拼接路径
set(ASCEND_INSTALL_PATH "${ASCEND_INSTALL_PATH}/latest")

add_library(aclrec SHARED acl_rec.cc)
target_include_directories(aclrec PRIVATE ${ASCEND_INSTALL_PATH}/include)

add_executable(sample_acl_rec main.cc)
target_link_libraries(sample_acl_rec aclrec)